package stackdemo;

import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Stack;

public class Test {

    //使用LinkedList模拟Stack
    public static void main(String[] args) {

        LinkedList<Integer> stack = new LinkedList<>();

        stack.push(1);
        stack.push(2);
        stack.push(3);
        stack.push(4);

        System.out.println(stack.pop());//4
        System.out.println(stack.pop());//3
        System.out.println(stack.peek());//2
        System.out.println(stack.peek());//2
    }


    //测试MyStack
    public static void main2(String[] args) {

        MyStack myStack = new MyStack();

        myStack.push(1);
        myStack.push(2);
        myStack.push(3);
        myStack.push(4);

        System.out.println(myStack.pop());//4
        System.out.println(myStack.pop());//3
        System.out.println(myStack.peek());//2
        System.out.println(myStack.peek());//2
    }


    //测试系统自带的Stack
    public static void main1(String[] args) {
        Stack<Integer> stack = new Stack<>();
        stack.push(12);
        stack.push(23);
        stack.push(34);
        stack.push(45);

        //pop()弹出栈顶元素
        System.out.println(stack.pop());//45
        System.out.println(stack.pop());//34

        //peek()获取栈顶元素，不删除
        System.out.println(stack.peek());//23
        System.out.println(stack.peek());//23
    }
}
